#pragma once

#include <QWidget>
#include "process_monitor.h"

class QPushButton;
class QLabel;
class QListWidget;
class SwitchButton;
class ProcessMonitor;
class QCheckBox;

class SystemTrayIcon;

class GuardianService : public QWidget
{
	Q_OBJECT

public:
	GuardianService(QWidget *parent = nullptr);
	~GuardianService();

	void killAllProcess();

protected:
	void closeEvent(QCloseEvent *event) override;

private slots:
	void onAddClicked();
	void onClearClicked();
	void onCloseAllClicked();
	void onOpenAllClicked();
	void onProcessStateChanged(ProcessMonitor::Process proc, bool status);
	void onAutoStartClicked(int status);

	void addListItem(QString appName, QString appPath, bool enableGuard);
	void setListItemStatus(QString appName, bool status);
	void setListItemGuardStatus(QString appName, bool status);

	bool runProcess(QString processPath);
	void killProcess(QString processName);
	

private:
	void initControls();
	void initLayout();
	void initData();
private:
	enum BtnType
	{
		Add,
		Clear,
		CloseAll,
		OpenAll,
		BtnTypeNum
	};

	enum LabelType {
		Number,
		AppName,
		AppPath,
		RunningState,
		EnableGuard,
		LabelTypeNum
	};

	QPushButton* btns_[BtnTypeNum];
	QLabel* labels_[LabelTypeNum];
	QListWidget* listWidget_;
	QCheckBox* chbAutoStart_;
	

	std::shared_ptr<ProcessMonitor> processMonitor_;
	std::shared_ptr<SystemTrayIcon> systemTrayIcon_;
};
